package com.itheima.controller;

import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.service.MemberService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: bowen
 * @Date: 2019/8/5 10:52
 * @Description:
 */
@RestController
@RequestMapping("/user")
public class UserController {
	/**
	 *  @描述：获取用户名
	 */
	@RequestMapping("/getUserName")
	public Result getUserName() {
		try {
			User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
			return new Result(true,MessageConstant.GET_USERNAME_SUCCESS,user.getUsername());
		} catch(Exception e){
			e.printStackTrace();
			return new Result(false, MessageConstant.GET_USERNAME_FAIL);
		}

	}
}
